package com.example.blew.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.blew.demo.model.User;
import com.example.blew.demo.service.WorkService;
import com.example.blew.demo.uitl.RrturnMesage;
import org.springframework.stereotype.Component;

/**
 * <p>
 * TODO
 * </p>
 *
 * @author chaodong.zeng@pcitc.com
 * @since 2022/9/6
 */
@Component
public class WorkServiceImpl implements WorkService {



    @Override
    public RrturnMesage select(int current, int size) {

        Page<User> page = new Page<>(current, size);
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
//        userMapper.selectPage(page, queryWrapper);

        return RrturnMesage.ok().data("current", page.getCurrent()).data("pages", page.getPages()).data("records", page.getRecords()).data("size", page.getSize()).data("total", page.getTotal());
    }

    @Override
    public boolean insertUser(User user) {
//        int insert = userMapper.insert(user);
        if (2 > 0) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public boolean deletUser(int id) {
//        int i = userMapper.deleteById(id);
        if (2 > 0) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public boolean updateUser(User user) {
        int i = 2;

        if (i > 0) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public User getUser(int id) {
        return null;
    }

    @Override
    public RrturnMesage conditionSelect(int current, int size, String name, int status) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.lambda()
                .like(!"".equals(name), "user_name", name)
                .eq(!"".equals(status), "status", status);

        Page<User> page = new Page<>(current, size);
//        userMapper.selectPage(page, queryWrapper);
        return RrturnMesage.ok().data("current", page.getCurrent()).data("pages", page.getPages()).data("records", page.getRecords()).data("size", page.getSize()).data("total", page.getTotal());

    }
}